<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>UMS</title>
    <link rel="stylesheet" th:href="@{/css/admin/base.css}">
    <link rel="stylesheet" th:href="@{/css/admin/app.css}">
</head>

<body>
<div class="app">
    <div class="app-header">
        <div class="logo"><img th:src="@{/img/logo.png}" alt=""></div>
        <div class="title">新潮账户管理系统</div>
        <div class="user">
            <span class="name">
                <i class="fa fa-user-o" aria-hidden="true"></i>
                <span class="name" th:text="${userName}">  </span>
                <i class="fa fa-caret-down"></i>
            </span>

            <ul>
                <li>
                    <div class="logout">退出</div>
                </li>
            </ul>
        </div>
    </div>
    <div class="app-container">
        <div class="app-aside menu-con"></div>
        <!--<div class="app-aside">-->
        <!--<div class="menu-group open">-->
        <!--<a class="menu-item">-->
        <!--<i class="icon fa fa-paper-plane"></i>-->
        <!--<div class="title">组织机构</div>-->
        <!--<div class="arrow fa fa-angle-down"></div>-->
        <!--</a>-->
        <!--<ul>-->
        <!--<a class="menu-item active" th:href="@{/page/deptMng}">-->
        <!--<div class="title">部门管理</div>-->
        <!--<div class="arrow"></div>-->
        <!--</a>-->
        <!--<a class="menu-item" th:href="@{/page/userMng}">-->
        <!--<div class="title">人员管理</div>-->
        <!--<div class="arrow"></div>-->
        <!--</a>-->
        <!--</ul>-->
        <!--</div>-->

        <!--<div class="menu-group">-->
        <!--<a class="menu-item">-->
        <!--<i class="icon fa fa-cog"></i>-->
        <!--<div class="title">角色权限管理</div>-->
        <!--<div class="arrow fa fa-angle-down"></div>-->
        <!--</a>-->
        <!--<ul>-->
        <!--<a class="menu-item" th:href="@{/page/roleMng}">-->
        <!--<div class="title">查看角色</div>-->
        <!--<div class="arrow"></div>-->
        <!--</a>-->
        <!--<a class="menu-item" th:href="@{/page/authMng}">-->
        <!--<div class="title">权限管理</div>-->
        <!--<div class="arrow"></div>-->
        <!--</a>-->
        <!--</ul>-->
        <!--</div>-->
        <!--</div>-->

        <div class="app-main">
            <!-- 初始页面地址 -->
            <iframe frameborder="0"></iframe>
        </div>
    </div>
</div>

<script th:src="@{/lib/jquery.min.js}"></script>
<script th:src="@{/js/popup.js}"></script>
<script th:src="@{/js/admin/index.js}"></script>
<script th:src="@{/js/admin/app.js}"></script>
<script th:src="@{/js/popup.js}"></script>
<script type="text/javascript">

    //菜单列表html
    menuData = {};
    menus = '';
    menuRootId = '';

    authBtns = null;

    $(function () {

        var initUrl = '';

        App.getData({
            url: App.apiUrlHost + '/getAuthInfo',
            data: {platformTag: 'portal'},
            dataType: 'json',
            success: function (result) {

                if (result.code == 0) {


                    $('.app-header .name').html(result['data']['user'].userName);

                    menuData = result.data.allAuth;

                    menuRootId = App.getParentArry(null, menuData)[0].authorityId;

                    GetData(menuRootId, menuData);

                    // console.log(menus);
                    $(".menu-con").append(menus);

                    $('#cid-' + initUrl).click();

                } else if (result.code == 403) {
                    popup.tipsTop({type: 'error', msg: result.msg});
                    setTimeout(function () {
                        $('.logout').click();
                    }, 1500);
                } else {
                    popup.tipsTop({type: 'error', msg: result.msg})
                }
            }
        });


        //根据菜单主键id生成菜单列表html
        //id：菜单主键id
        //arry：菜单数组信息
        function GetData(id, arry) {
            var childArry = App.getParentArry(id, arry);
            if (childArry.length > 0) {


                for (var i in childArry) {

                    if (id == menuRootId) {
                        menus += '<div class="menu-group">';
                    } else {
                        menus += '<ul>';
                    }


                    var childs = App.getParentArry(childArry[i].authorityId, arry);

                    initUrl = initUrl ? initUrl : (childArry[i].url ? childArry[i].authorityId : '');

                    menus += '<a class="menu-item" href="' + (childArry[i].url || '#') + '" data-id="' + childArry[i].authorityId + '" id="cid-' + childArry[i].authorityId + '">' +
                        '   <i class="icon fa fa-' + childArry[i].icon + '"></i>' +
                        '       <div class="title">' + childArry[i].authorityName + '</div>' +
                        '   <div class="arrow ' + (childs.length > 0 ? 'fa fa-angle-down' : '') + '"></div>' +
                        '</a>';

                    GetData(childArry[i].authorityId, arry);

                    if (id == menuRootId) {
                        menus += '</div>';
                    } else {
                        menus += '</ul>';
                    }
                }


            }
        }

        //根据菜单主键id获取下级菜单
        //id：菜单主键id
        //arry：菜单数组信息
        // function GetParentArry(id, arry) {
        //     var newArry = new Array();
        //     for (var i in arry) {
        //         if (arry[i].parentId == id && arry[i].type != 3)
        //             newArry.push(arry[i]);
        //     }
        //     return newArry;
        // }


    })
    $('.logout').click(function () {

        App.getData({
            url: App.apiUrlHost + '/logout',
            data: {platformTag: 'portal'},
            dataType: 'json',
            success: function (result) {
                if (result.code == 0) {
                    location.href = result.data;
                } else {
                    popup.tipsTop({type: 'error', msg: result.msg})
                }
            }
        })
    });
</script>
</body>

</html>